import cTitle from "components/title";
import yzBlank from "components/ui_components/yz_blank";

export default {
  data() {
    return {
      course_goods:{},
      level_data: [],
      level_type:'',
      member_info:{},
      price:0,
      current_index:0,
    };
  },
  computed:{
    level_name(){
      let name = '';
      this.level_data.forEach((item,i)=>{
        if(i+1!==this.level_data.length){
          name+=item.level_name+'、';
        }else{
          name+=item.level_name;
        }
      })
      return name;
    }
  },
  methods: {
    choose(i){
      this.current_index = i;
    },
    //获取会员升级商品信息
    getMemberUpdate() {
      $http
        .get("plugin.video-demand.api.watch-level.condition", {
          goods_id: this.$route.params.goods
        })
        .then(response => {
          if (response.result == 1) {
            if (!this.fun.isTextEmpty(response.data)) {
              let { course_goods,level_data,level_type,member_info } = response.data;
              this.course_goods = course_goods;
              this.level_data = level_data;
              this.level_type = level_type;
              this.member_info = member_info;
            }
          }
          else{
            this.$dialog.alert({message:response.msg});
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    goto(){
      this.$router.push(this.fun.getUrl("home"));
    },
    gotoBuy(id) {
      this.$router.push(this.fun.getUrl("goods", { id: id }));
    },

    // 跳转充值页, 携带充值数量
    toRecharge(num){
      this.$router.push(this.fun.getUrl("balance_recharge", { num: num }));
    },
    getGoods(){
      $http.get("plugin.video-demand.api.video-course-goods.get-course-goods-detail",{goods_id:this.$route.params.goods}).then(res=>{
        if(res.result!==1){
          return this.$toast(res.msg);
        }
        let {has_one_goods} = res.data;
        this.price = has_one_goods.price;
        console.log(res.data,"data===");
      })
    },
  },
  activated() {
    this.course_goods = {};
    this.level_data=[];
    this.level_type='';
    this.getMemberUpdate();
    this.getGoods();
  },

  components: { cTitle, yzBlank }
};
